package org.example.controller;

import org.springframework.web.bind.annotation.*;
import java.util.*;

@RestController
@RequestMapping("/setmeal")
@CrossOrigin(origins = "*")
public class SetmealController {

    @GetMapping("/list")
    public Map<String, Object> getSetmealList(@RequestParam(required = false) Long categoryId,
                                             @RequestParam(required = false) Integer status) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "查询成功");
        
        // 模拟套餐数据
        List<Map<String, Object>> setmeals = new ArrayList<>();
        
        Map<String, Object> setmeal1 = new HashMap<>();
        setmeal1.put("id", 1L);
        setmeal1.put("name", "经典套餐A");
        setmeal1.put("categoryId", 4L);
        setmeal1.put("price", 5800); // 58.00元
        setmeal1.put("image", "demo4.png");
        setmeal1.put("description", "宫保鸡丁 + 麻婆豆腐 + 米饭");
        setmeal1.put("status", 1);
        setmeal1.put("saleNum", 45);
        setmeal1.put("number", 0);
        setmeals.add(setmeal1);
        
        Map<String, Object> setmeal2 = new HashMap<>();
        setmeal2.put("id", 2L);
        setmeal2.put("name", "经典套餐B");
        setmeal2.put("categoryId", 4L);
        setmeal2.put("price", 6800); // 68.00元
        setmeal2.put("image", "demo4.png");
        setmeal2.put("description", "红烧肉 + 麻婆豆腐 + 米饭 + 汤");
        setmeal2.put("status", 1);
        setmeal2.put("saleNum", 32);
        setmeal2.put("number", 0);
        setmeals.add(setmeal2);
        
        result.put("data", setmeals);
        return result;
    }

    @GetMapping("/page")
    public Map<String, Object> getSetmealPage(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Long categoryId) {
        
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "查询成功");
        
        // 模拟分页数据
        Map<String, Object> data = new HashMap<>();
        data.put("records", new Object[0]);
        data.put("total", 0);
        data.put("current", page);
        data.put("size", pageSize);
        result.put("data", data);
        
        return result;
    }

    @GetMapping("/{id}")
    public Map<String, Object> getSetmealById(@PathVariable Long id) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "查询成功");
        result.put("data", new HashMap<>());
        return result;
    }

    @GetMapping("/dish/{id}")
    public Map<String, Object> getSetmealDishById(@PathVariable Long id) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "查询成功");
        
        // 模拟套餐菜品数据
        List<Map<String, Object>> dishes = new ArrayList<>();
        
        Map<String, Object> dish1 = new HashMap<>();
        dish1.put("id", 1L);
        dish1.put("name", "宫保鸡丁");
        dish1.put("price", 2800);
        dish1.put("image", "demo1.png");
        dish1.put("description", "经典川菜，鸡肉嫩滑，花生香脆");
        dish1.put("copies", 1);
        dishes.add(dish1);
        
        Map<String, Object> dish2 = new HashMap<>();
        dish2.put("id", 2L);
        dish2.put("name", "麻婆豆腐");
        dish2.put("price", 1800);
        dish2.put("image", "demo2.png");
        dish2.put("description", "麻辣鲜香，豆腐嫩滑");
        dish2.put("copies", 1);
        dishes.add(dish2);
        
        result.put("data", dishes);
        return result;
    }

    @PostMapping
    public Map<String, Object> addSetmeal(@RequestBody Map<String, Object> setmeal) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "添加成功");
        return result;
    }

    @PutMapping
    public Map<String, Object> updateSetmeal(@RequestBody Map<String, Object> setmeal) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "修改成功");
        return result;
    }

    @DeleteMapping
    public Map<String, Object> deleteSetmeal(@RequestParam String ids) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "删除成功");
        return result;
    }

    @PostMapping("/status/{status}")
    public Map<String, Object> updateStatus(@PathVariable int status, @RequestParam String ids) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "状态修改成功");
        return result;
    }
}

